#include "music.h"

ALLEGRO_SAMPLE* eat_female;
ALLEGRO_SAMPLE* eat_male;
ALLEGRO_SAMPLE* checkmate_female;
ALLEGRO_SAMPLE* checkmate_male;
ALLEGRO_SAMPLE* uplift_piece;
ALLEGRO_SAMPLE* lay_piece;
ALLEGRO_SAMPLE* select_;
ALLEGRO_SAMPLE* confirm;
ALLEGRO_SAMPLE* shout_chess;
ALLEGRO_SAMPLE* shout_start;
ALLEGRO_AUDIO_STREAM* bgm;

void bgm_init(){
    bgm = al_load_audio_stream("res/bgm.opus", 2, 1024);
    if(!bgm)
    {
        printf("couldn't load bgm\n");
        exit(1);
    }
    al_set_audio_stream_playmode(bgm, ALLEGRO_PLAYMODE_LOOP);
    al_attach_audio_stream_to_mixer(bgm, al_get_default_mixer());
}

void sfx_init(){
    eat_female = al_load_sample("res/eat_female.opus");
    eat_male = al_load_sample("res/eat_male.opus");
    checkmate_female = al_load_sample("res/checkmate_female.opus");
    checkmate_male = al_load_sample("res/checkmate_male.opus");
    uplift_piece = al_load_sample("res/uplift_piece.opus");
    lay_piece = al_load_sample("res/lay_piece.opus");
    select_ = al_load_sample("res/select.opus");
    confirm = al_load_sample("res/confirm.opus");
    shout_chess = al_load_sample("res/shout_chess.opus");
    shout_start = al_load_sample("res/shout_start.opus");
}

void play_chess(){
    al_play_sample(shout_chess, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_start(){
    al_play_sample(shout_start, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_eat(bool is_male){
    if(is_male) al_play_sample(eat_male, 1.0, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
    else
        al_play_sample(eat_female, 1.0, -0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_checkmate(bool is_male){
    if(is_male) al_play_sample(checkmate_male, 1.0, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
    else
        al_play_sample(checkmate_female, 1.0, -0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_uplift_piece(){
    al_play_sample(uplift_piece, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_lay_piece(){
    al_play_sample(lay_piece, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_select(){
    al_play_sample(select_, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}

void play_confirm(){
    al_play_sample(confirm, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
}